let userinfo = new Object();
let roles = new Array();
let roleId = null;

export async function onGetUserinfoData() {
	if (userinfo && userinfo.userId) {
		userinfo = await uni.getStorageSync('userinfo') || '';
	}
	return userinfo;
}

export async function onSetUserinfoData(info) {
	return await uni.setStorageSync('userinfo', userinfo = info)
}

export function onDeleteUserinfoData() {
	userinfo = new Object()
	uni.removeStorageSync('userinfo');
}

export function onHasUserinfoData() {
	return userinfo.userId
}



export async function onGetRoleIdData() {
	if (!roleId) {
		roleId = await uni.getStorageSync('roleId') || null;
	}
	return roleId
}

export async function onSetRoleIdData(id) {	
	return await uni.setStorageSync('roleId', roleId = id)
}

export function onDeleteRoleIdData() {
	roleId = null
	uni.removeStorageSync('roleId');
}



export async function onGetRolesData() {
	if (roles && roles.length == 0) {
		roles = await uni.getStorageSync('roles') || '';
	}
	return roles;
}

export async function onSetRolesData(data) {
	return await uni.setStorageSync('roles', roles = data)
}

export function onDeleteRolesData() {
	roles = new Array();
	uni.removeStorageSync('roles');
}